//Archivo .C del Driver de los Motores



#include "Motores_Driver.h"
#include <delays.h>

T_UBYTE MotorState = 0;

void initMotores(void)
{
	GPDconf('D',0b10110000);
}

void UpMotores(T_UBYTE lub_rpm, T_UBYTE tipo_motor)
{

	switch(MotorState)
	{
		case 0:	GPDout('D',0x03);
				MotorState = 1;
				Delay10KTCYx(lub_rpm);
			break;
		case 1: 	GPDout('D',0x06);
				MotorState = 2;
				Delay10KTCYx(lub_rpm);
			break;
		case 2:	GPDout('D',0x0C);
				MotorState = 3;
				Delay10KTCYx(lub_rpm);
			break;
		case 3:	GPDout('D',0x09);
				MotorState = 0;
				Delay10KTCYx(lub_rpm);
			break;
	}
}


void DownMotores(T_UBYTE lub_rpm, T_UBYTE tipo_motor)
{

	switch(MotorState)
	{
		case 3:	GPDout('D',0x03);
				MotorState = 0;
				Delay10KTCYx(lub_rpm);
			break;
		case 2: 	GPDout('D',0x06);
				MotorState = 3;
				Delay10KTCYx(lub_rpm);
			break;
		case 1:	GPDout('D',0x0C);
				MotorState = 2;
				Delay10KTCYx(lub_rpm);
			break;
		case 0:	GPDout('D',0x09);
				MotorState = 1;
				Delay10KTCYx(lub_rpm);
			break;
	}
}


void BiDownMotores(T_UBYTE lub_rpm, T_UBYTE tipo_motor)
{

	switch(MotorState)
	{
		case 0:	GPDout('D',0x0A);
				MotorState = 1;
				Delay10KTCYx(lub_rpm);
			break;
		case 1: 	GPDout('D',0x09);
				MotorState = 2;
				Delay10KTCYx(lub_rpm);
			break;
		case 2:	GPDout('D',0x05);
				MotorState = 3;
				Delay10KTCYx(lub_rpm);
			break;
		case 3:	GPDout('D',0x06);
				MotorState = 0;
				Delay10KTCYx(lub_rpm);
			break;
	}
}


void BiUpMotores(T_UBYTE lub_rpm, T_UBYTE tipo_motor)
{
	switch(MotorState)
	{
		case 3:	GPDout('D',0x0A);
				MotorState = 0;
				Delay10KTCYx(lub_rpm);
			break;
		case 2: 	GPDout('D',0x09);
				MotorState = 3;
				Delay10KTCYx(lub_rpm);
			break;
		case 1:	GPDout('D',0x05);
				MotorState = 2;
				Delay10KTCYx(lub_rpm);
			break;
		case 0:	GPDout('D',0x06);
				MotorState = 1;
				Delay10KTCYx(lub_rpm);
			break;
	}
}